package com.df.gameai.config;

import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.ChatMessage;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.store.memory.chat.ChatMemoryStore;
import lombok.Builder;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
@Builder
public class SimpleChatMemery implements ChatMemory {
    private String id;
    private List<ChatMessage> msgs = new ArrayList<>();

    @Override
    public Object id() {
        return id;
    }

    @Override
    public void add(ChatMessage chatMessage) {
        //TODO 超过限制条数时，最旧的消息进行总结压缩处理，玩家提问最好不处理，将token太长的消息处理掉
        //SystemMessage只能有条，后添加的会覆盖旧的
        msgs.add(chatMessage);
    }

    @Override
    public List<ChatMessage> messages() {
        return msgs;
    }

    @Override
    public void clear() {
        msgs.clear();
    }
}
